package com.cnswhy.cloud.server.system.controller;

import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.server.system.entity.SystemRoleAuthority;
import com.cnswhy.cloud.server.system.dto.SystemRoleAuthoritySaveDTO;
import com.cnswhy.cloud.server.system.dto.SystemRoleAuthorityUpdateDTO;
import com.cnswhy.cloud.server.system.dto.SystemRoleAuthorityPageDTO;
import com.cnswhy.cloud.server.system.service.SystemRoleAuthorityService;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.cnswhy.cloud.common.core.base.controller.SuperController;
import com.cnswhy.cloud.common.core.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
//import com.github.zuihou.security.annotation.PreAuth;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 角色的资源
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-13
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/systemRoleAuthority")
@Api(value = "SystemRoleAuthority", tags = "角色的资源")
//@PreAuth(replace = "systemRoleAuthority:")
public class SystemRoleAuthorityController extends SuperController<SystemRoleAuthorityService, Long, SystemRoleAuthority, SystemRoleAuthorityPageDTO, SystemRoleAuthoritySaveDTO, SystemRoleAuthorityUpdateDTO> {


    /**
     * 查询指定角色关联的菜单和资源
     *
     * @param roleId 角色id
     * @return 查询结果
     */
    @ApiOperation(value = "查询指定角色关联的菜单和资源", notes = "查询指定角色关联的菜单和资源")
    @GetMapping("/{roleId}")
    //@SysLog(value = "'查询指定角色关联的菜单和资源", response = false)
    public R<List<SystemRoleAuthority>> queryByRoleId(@PathVariable Long roleId) {
        return R.success(baseService.list(Wraps.<SystemRoleAuthority>lbQ().eq(SystemRoleAuthority::getRoleId, roleId)));
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<SystemRoleAuthority> systemRoleAuthorityList = list.stream().map((map) -> {
            SystemRoleAuthority systemRoleAuthority = SystemRoleAuthority.builder().build();
            return systemRoleAuthority;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(systemRoleAuthorityList));
    }
}
